package diploma.kisel.modelas.domain;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Domain class for Concept (table - concept).
 * 
 * @author Nikolay Kisel
 *
 */
@Entity
@Table(name = "concept")
@NamedQueries({
		@NamedQuery(name = "Concept.findAll", query = "select c from Concept c"),
		@NamedQuery(name = "Concept.findById", query = "select c from Concept c where c.id = :id"),
		@NamedQuery(name = "Concept.findByProject", query = "select c from Concept c where c.project = :project")})
public class Concept {

	private Integer id;
	private String number;

	// for many to one mapping
	private Project project;
	// for one to many mapping
	private Set<Workstation> workstations = new HashSet<Workstation>();

	public Concept() {

	}

	public Concept(Integer id, String number) {
		this.id = id;
		this.number = number;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id_concept")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "number")
	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	@ManyToOne
	@JoinColumn(name = "id_project")
	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	@OneToMany(mappedBy = "concept", cascade = CascadeType.ALL, orphanRemoval = true)
	public Set<Workstation> getWorkstations() {
		return workstations;
	}

	public void setWorkstations(Set<Workstation> workstations) {
		this.workstations = workstations;
	}

	@Override
	public String toString() {
		return number;
	}

}
